home *** CD-ROM | disk | FTP | other *** search
- Path: rap.SanDiegoCA.ATTGIS.COM!news
- From: borisb@sd.znet.com (Boris Burtin)
- Newsgroups: comp.lang.c++,rb.technical
- Subject: Can copy constructor and operator= share code?
- Date: Wed, 28 Feb 1996 22:19:28 GMT
- Organization: Lunapark Studios
- Message-ID: <4h2kcn$40d@rap.SanDiegoCA.ATTGIS.COM>
- NNTP-Posting-Host: borisbpc.sandiegoca.attgis.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- I have noticed that a copy constructor and operator= perform pretty
- much the same function. The code I wrote for my class simply copies
- each member variable from one class to the other.
-
- Is there a way for the one of the two functions to call the other, to
- avoid duplicate code? I have tried calling the copy constructor from
- operator=, but nothing happens. I've gotten around this problem by
- creating a private Copy() function, which is called by both the copy
- constructor and operator=. Is there another way?
-
- Thanks,
-
- Boris
-
-
-